package com.design.ObserverMode.mode;

import com.design.ObserverMode.demo.User;

import java.util.ArrayList;
import java.util.List;

public class MyRegSubject implements RegSubject{

    private List<MyRegObserver> myRegObserverList = new ArrayList<MyRegObserver>();

    @Override
    public void reg(MyRegObserver myRegObserver) {
        myRegObserverList.add(myRegObserver);
    }

    @Override
    public void remove(MyRegObserver myRegObserver) {
        myRegObserverList.remove(myRegObserver);
    }

    @Override
    public void notifyAll(User user) {
        for (MyRegObserver myObserver : myRegObserverList) {
            myObserver.regHandler(user);
        }
    }
}
